class Queue {
  constructor() {
    this.items = [];
  }

  enqueue(element) {
    this.items.push(element);
  }

  dequeue() {
    return this.items.shift();
  }

  size() {
    return this.items.length;
  }

  isEmpty() {
    return this.items.length === 0;
  }
}

function hotPotato(names, num) {
  const queue = new Queue();

  // 所有人入队
  for (let name of names) {
    queue.enqueue(name);
  }

  // 模拟传花
  while (queue.size() > 1) {
    for (let i = 0; i < num; i++) {
      // 将队首元素移动到队尾
      queue.enqueue(queue.dequeue());
    }

    // 淘汰当前持花者
    const eliminated = queue.dequeue();
    console.log(`${eliminated} 被淘汰了`);
  }

  // 最后剩下的人
  return queue.dequeue();
}

// 示例
const players = ["Alice", "Bob", "Cathy", "David", "Ella"];
const winner = hotPotato(players, 7);
console.log(`最后的胜利者是：${winner}`);
